Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling a getter method from a parent abstract class
    text
    copied!<p>This is how my classes look like:</p> <pre><code>public abstract class BaseForm extends Z{ protected String someString; public String getSomeString(){ return this.someString; } public void setSomeString(String some){ this.someString = some; } } </code></pre> <hr> <pre><code>public abstract class AdvancedForm extends BaseForm{ protected Something selectedThing; protected List&lt;Something&gt; listOfThings; public Something getSelectedThing(){ return this.selectedThing; } public void setSelectedThing(Something thing){ this.selectedThing = thing; } public List&lt;Something&gt; getListOfThings(){ return this.listOfThings; } public void setListOfThings(List&lt;Something&gt; list){ this.listOfThings = list; } } </code></pre> <hr> <pre><code>public class FinalForm extends AdvancedForm{ //Lot of stuff done here } </code></pre> <p>So I have something similar to what you can see above. The problem comes when I create a JSP and it tries to call the <code>get/setListOfThings</code> methods. </p> <pre><code>&lt;html:html&gt; ... &lt;html:select name="FinalForm" property="selectedThing"&gt; &lt;html:optionsCollection name="FinalForm" property="listOfThings" label="label" value="value" /&gt; &lt;/html:select&gt; ... &lt;/html:html&gt; </code></pre> <p>I know I'm missing something here (<code>struts-config.xml</code> and <code>tiles-def.xml</code> exist and are correct), but my point of view is that struts should be calling the <code>FinalForm</code>'s <code>setListOfThings</code> method. And this should be calling the <code>AdvancedForm</code>'s <code>setListOfThings</code> method (which is the one implemented) because <code>FinalForm</code> is extending <code>AdvancedForm</code> and I'm not overriding the method in the <code>FinalForm</code>.</p> <p>Anyhow, this is not working and I don't know what's wrong. The only way it works is if I override the method and call explicitly the <code>setListOfThings</code> from the <code>AdvancedForm</code>.</p> <pre><code>public class FinalForm extends AdvancedForm{ //... public List&lt;Something&gt; getListOfThings(){ return super.getListOfThings(); } } </code></pre> <p>I want to avoid that overriding because the point of creating the <code>AdvancedForm</code> class is to remove a lot of functionality that most of my forms are using (but not all of them, this is the reason for the existence of <code>BaseForm</code> and <code>AdvanceForm</code> classes).</p> <p>Any ideas why this is not working? Any ideas to improve this? Anyone can explain to me what I'm doing wrong? Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload