Domanda

I may be asking a basic question but I did not get any answers so far for it.

<s:radio label="Gender" name="gender" list="{'male','female'}" />
</s:form>

in the above code name="gender" is the name of the action class' attribute now if I happen to change this name in action class I must change it in my JSP (view) & vice-verse & so there is a dependency, so how the two layers View & Model are independent?

Please tell or provide links,thank you.

È stato utile?

Soluzione

If you treat a View as a Model you can't get independence. The Model (if you have a model) is actually tightly integrated with the persistence layer. Struts2 is a strict front-end framework, it doesn't contain models other than View models. So, staying independent it integrates with other frameworks like Hibernate or JPA where the model is mapped to the persistence layer. All the mappings you perform in Struts2 is between a View and Controller.

The links:

Altri suggerimenti

That is why MVC concept arises. Most of the frameworks implementation based on Model-View-Controller basis. Initally in Jsp/Servlet projects database connection achieved within jsp/servlet. The intention of Modern frameworks(Spring, Struts) are to separate the business logic from view. Hope the links will explain you more.. MVC-Wiki and Link.

you may write the radio button in simple html format like <input type='radio' name='abc'/> instead of using jsp's native syntax in view page. then 'name' attribute of the input element will be independent of the model. and to access the value of this element in the controller class we can use that 'name' attribute.

thanks

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top