Hi Daniel-

The idea of a "smart bean" which knows how to render itself is a
pretty cool idea, and it's a clean idea conceptually. But, I think the
Struts framework and struts jsp tags removes a lot of the hassle
because of what it gives you out of the box.

I've been faced with the same situation, and we used the same jsp for
view and edit mode, with the html markup/form/etc., based on if you
are in edit or view mode, and just tweak the output. For example,
<td>A Field:</td>
<td>
<c:if test="${inAddEditMode}">
  <html:text ... property="aField"/>
</c:if>
<c:if test="${not inAddEditMode}">
  <c:out value="${formBean.aField}"/>
</c:if>
</td>

I think you're going to find that adding a ton of complexity to
generate HTML in a form bean (or helper or wherever) and recreating
everything that comes 'for free' with Struts isn't worth saving one
step in your plan below (changing custom jsp view logic), especially
following my example above.

Also a suggestion, you can condense steps 3 and 4 by using a
dynaFormBean and then in the action map the struts form bean to your
user bean using Jakarta BeanUtils methods to copy back and forth, so
you will never have to explicitly declare setters and getters for most
of your fields. You'll only need custom logic (in your action or
better in a stateless helper class) to set a declared form bean field
when automatic translation can't occur, such as datatypes are
incompatible or you have a form field set based on some fields'
values.

Another idea, assume your User bean is populated from the database
based on the data returned (again with bean utils) and the new
field(s) are added in a DAO/persistence layer which has to be done
anyway. In this case the only changes required in step 1 are adding a
private field and get/set methods, which is pretty trivial.

It looks like you're adding a lot of complexity for not much gain.
Maybe I'm missing something though, and the concept does sound
interesting too, it's certainly thought-provoking!

-ed

On 7/22/05, Daniel Łaś <[EMAIL PROTECTED]> wrote:
> Well, I thing about something else.
> 
> If UserView bean can generate HTML form fields dependig on User
> attributes, one for adding, another one for editing I could only change
> my User bean (model) and my view layer will work without change. I think
> that it is possible to write action that will work with this (controller
> layer) without change too.
> 
> Lets say, I add new attribute to User, eg. lastName.
> I have to:
> 1. modify User bean code (model)
> 2. then modify appropriate jsp pages, first with edit form, second with
> add form
> 3. then modify struts-config.xml (form properties)
> 4. then modify appropriate form bean
> 5. then modify two actions (one for edit, one for add operation)
> 
> It would be nice, to change only my model and have view layer adapting
> to model.
> 
> Mabe I'm re-inventing the wheel. If so, please tell me. I'm new to
> struts and Java technologies, just trying to make right decisions before
> my projects start.
> 
> Regards
>

Reply via email to