You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ciaran Hanley <ci...@sentenial.ie> on 2004/01/09 00:28:24 UTC

Three JSPs in one

Hi 
 
In my application I am currently performing add user, view user and edit
user functions on separate JSPs.
 
So I have:         adduser.jsp to add users through a form
viewuser.jsp to view a users details in plain text
edituser.jsp to edit a users details in a populated form
 
Instead of having three different pages I would like to perform these
functions all on one page, the thing is I don't want to use any
scriptlets on my page.
Is there away of using the html-logic tags to test for which task I
would like to perform, or some other method I can use to do this, I cant
figure it out.
 
Basically something that will do
 
If(select view)
{
      show details on page
}
else If(select edit)
{
      show users details in a form for update
}
else
{
      show form on page to add user
}
 
I was thinking some sort of logic
 
<logic:present (view)>
  ..view details
</logic:present>
 
<logic:present (add)>
  ..view details
</logic:present>
 
<logic:present (edit)>
  ..view details
</logic:present>
 
Anybody done this before?
 
 
Many Thanks
Ciaran

bean:include problem

Posted by Lucas Gonzalez <lu...@convergia.com.ar>.
Hi!
I´m new to struts and I have a small problem.
I want to include a jsp ( navBar.jsp ) that has something like:
    <snipet>
        <html:link action="/Login.do"><bean:message
key="navigation.customerData"/></html:link>
    </snipet>

So I did a little research, and tried using
    <bean:include forward="navBar" id="navBar" />
unfortunately I do not understand what the id attribute is for.
the docs state:
    "Specifies the name of the scripting variable (and associated page scope
attribute) that will be made available with the value of the specified web
application resource."

and still I do not understand what to do with it.

I can´t get it to work, it does not throw any error, but the navBar.jsp is
not included into the main page.

There´s anything I´m missing here?
I wondered if anyone could give me some help or maybe point to some
documentation that might be useful....

btw... here is the globalForward just in case it might help to clarify my
problem.
        <forward name="navBar" path="/pages/navBar.jsp"/>

Thanks a lot,
and Best Regards,

Lucas






---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Three JSPs in one

Posted by Richard Hightower <rh...@arc-mind.com>.
I've done this before with tiles.

You have a nested tile that displays the field. One for editing, one for
viewing.

You have a base definition that uses the field display tile as an argument.

You create definitions that extend the base definition passing the correct
display display definition.

see http://www.arc-mind.com/downloads.htm#TilesTutorial for more detail....

;)

Rick Hightower
Developer

Struts/J2EE training -- http://www.arc-mind.com/strutsCourse.htm

Struts/J2EE consulting --
http://www.arc-mind.com/consulting.htm#StrutsMentoring

-----Original Message-----
From: Ciaran Hanley [mailto:ciaran.hanley@sentenial.ie]
Sent: Thursday, January 08, 2004 4:28 PM
To: Struts User Mailing List
Subject: Three JSPs in one


Hi

In my application I am currently performing add user, view user and edit
user functions on separate JSPs.

So I have:         adduser.jsp to add users through a form
viewuser.jsp to view a users details in plain text
edituser.jsp to edit a users details in a populated form

Instead of having three different pages I would like to perform these
functions all on one page, the thing is I don't want to use any
scriptlets on my page.
Is there away of using the html-logic tags to test for which task I
would like to perform, or some other method I can use to do this, I cant
figure it out.

Basically something that will do

If(select view)
{
      show details on page
}
else If(select edit)
{
      show users details in a form for update
}
else
{
      show form on page to add user
}

I was thinking some sort of logic

<logic:present (view)>
  ..view details
</logic:present>

<logic:present (add)>
  ..view details
</logic:present>

<logic:present (edit)>
  ..view details
</logic:present>

Anybody done this before?


Many Thanks
Ciaran


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Three JSPs in one

Posted by Wiebe de Jong <wi...@shaw.ca>.
Here is a repost (from Oct 22) of some example code I developed that does
exactly this.

---

Or you could have multiple mappings pointing to one action and one jsp.

Each mapping would set a different value for the parameter, the action would
use the parameter to set some beans, and the jsp would use the beans to
control the output.

As in the following code:

----------

struts-config.xml:

<!-- Execute the Item Add action -->
<action path="/itemAdd"
  type="com.myco.myapp.ItemLoadAction"
  name="itemForm"
  parameter="add"
  scope="session"
  validate="false">
<forward name="success" path="item.page"/>
<forward name="failure" path="error.page"/>
</action>

<!-- Execute the Item Change action -->
<action path="/itemChange"
  type="com.myco.myapp.ItemLoadAction"
  name="itemForm"
  parameter="change"
  scope="session"
  validate="false">
<forward name="success" path="item.page"/>
<forward name="failure" path="error.page"/>
</action>

<!-- Execute the Item Inspect action -->
<action path="/itemInspect"
  type="com.myco.myapp.ItemLoadAction"
  name="itemForm"
  parameter="inspect"
  scope="session"
  validate="false">
<forward name="success" path="item.page"/>
<forward name="failure" path="error.page"/>
</action>
		    
<!-- Execute the Item Delete action -->
<action    path="/itemDelete"
  type="com.myco.myapp.ItemLoadAction"
  name="itemForm"
  parameter="delete"
  scope="session"
  validate="false">
<forward name="success" path="item.page"/>
<forward name="failure" path="error.page"/>
</action>
		    
----------

ItemLoadAction.java:

String action = mapping.getParameter();

// set ACID properties
if ("add".equals(action))
  session.setAttribute("mode.form", "add");
if ("change".equals(action))
  session.setAttribute("mode.form", "change");
if ("inspect".equals(action))
  session.setAttribute("mode.form", "inspect");
if ("delete".equals(action))
  session.setAttribute("mode.form", "delete");

// set view properties
if ("delete".equals(action) || "inspect".equals(action))
  session.setAttribute("mode.fields", "read");
else
  session.setAttribute("mode.fields", "update");

----------

item.jsp:

<tr>
  <td><bean:message key="item.date"/></td>
  <td align="left">
    <logic:equal name="mode.fields" value="read">
      <html:text property="date" disabled="true" maxlength = "8" size =
"8"/>
    </logic:equal>
    <logic:equal name="mode.fields" value="update">
      <html:text property="date" maxlength = "8" size = "8"/>
    </logic:equal>
  </td>
</tr>

<tr><td align="right">
  <logic:equal name="mode.form" value="add">
    <html:submit> <bean:message key="button.add"/> </html:submit>
    <html:submit> <bean:message key="button.cancel"/> </html:submit>
  </logic:equal>

  <logic:equal name="mode.form" value="change">
    <html:submit> <bean:message key="button.update"/> </html:submit>
    <html:submit> <bean:message key="button.cancel"/> </html:submit>
  </logic:equal>

  <logic:equal name="mode.form" value="delete">
    <bean:message key="warning.delete"/>&nbsp;&nbsp;
    <html:submit> <bean:message key="button.delete"/> </html:submit>
    <html:submit> <bean:message key="button.cancel"/> </html:submit>
  </logic:equal>

  <logic:equal name="mode.form" value="inspect">
    <html:submit> <bean:message key="button.ok"/> </html:submit>
  </logic:equal>
</td></tr>


-----Original Message-----
From: Ciaran Hanley [mailto:ciaran.hanley@sentenial.ie] 
Sent: Thursday, January 08, 2004 3:28 PM
To: Struts User Mailing List
Subject: Three JSPs in one

Hi 
 
In my application I am currently performing add user, view user and edit
user functions on separate JSPs.
 
So I have:         adduser.jsp to add users through a form
viewuser.jsp to view a users details in plain text
edituser.jsp to edit a users details in a populated form
 
Instead of having three different pages I would like to perform these
functions all on one page, the thing is I don't want to use any
scriptlets on my page.
Is there away of using the html-logic tags to test for which task I
would like to perform, or some other method I can use to do this, I cant
figure it out.
 
Basically something that will do
 
If(select view)
{
      show details on page
}
else If(select edit)
{
      show users details in a form for update
}
else
{
      show form on page to add user
}
 
I was thinking some sort of logic
 
<logic:present (view)>
  ..view details
</logic:present>
 
<logic:present (add)>
  ..view details
</logic:present>
 
<logic:present (edit)>
  ..view details
</logic:present>
 
Anybody done this before?
 
 
Many Thanks
Ciaran


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org