You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Dean Hiller <de...@xsoftware.biz> on 2006/03/30 15:25:16 UTC
design question...filling in bean, posting
I am have this
treeBean -> tree.jsp
folderBean -> editFolder.jsp
When someone click on the tree.jsp, I need to fill in the folderBean
with the folderName, folderId, and folderDescription properties. What
is the best design for this? I am quite the newb to all this. I am
thinking session state right now is easiest, and I retrieve the
folderBean in treeBean.editFolder() action method and fill it in, so
when editFolder.jsp renders, it renders with the correct data. Please
suggest alternatives and what you think is the best.
Lastly, what about dealing with someone who opens up two windows(which
would be in the same session). Couldn't he possibly step on himself
since I am storing this stuff in the session above?
thanks,
dean
Re: design question...filling in bean, posting
Posted by Dean Hiller <de...@xsoftware.biz>.
this is much better than what i just stumbled upon I think then,
correct? Here is what I just did (and it actually worked to my
surprise)....
FacesContext ctx = FacesContext.getCurrentInstance();
ExternalContext extCtx = ctx.getExternalContext();
Map<Object, Object> sessionMap = extCtx.getApplicationMap();
ProjectBean projBean = new ProjectBean();
projBean.setNodeId(nodeId);
projBean.setName("desc="+node.getDescription());
projBean.setDescription("TempDescriptionDean");
sessionMap.put("projectBean", projBean);
I like your way better though! Thank you very much!!!
thanks,
dean
Ricardo Tercero Lozano wrote:
> You can get a reference to a managed bean defined in faces-config.xml
> this way:
>
> ValueBinding bind =
> FacesContext.getCurrentInstance().getApplication()
> .createValueBinding("#{myBean}");
>
> MyBean myBean = (MyBean)bind.getValue(this.facesContext);
>
> It can be done too using the variableResolver. El expression can
> reference a managed bean or a property (eg. #{myBean.myProperty}. You
> can get an set a value.
>
> If myBean doesn't exists, Faces creates a new instance and returns it.
>
>
>
>
>
> On 3/31/06, *Dean Hiller* < dean@xsoftware.biz
> <ma...@xsoftware.biz>> wrote:
>
> I am not sure I understand. In treeBean, how do I get a
> folderBean(that
> will be created if it doesn't exist). I was looking at
>
> FacestContext
> ExternalContext
>
> I could not find any methods that I can use to look up
> "folderBean"(and
> create a FolderBean if one doesn't exist), but I suppose I am just
> missing this. Could you point me to the method?
>
> LASTLY, can this bean be request scoped in this case then? it sounds
> like it to me, but I am a newb in this stuff.
>
> thanks,
> dean
>
> Ricardo Tercero Lozano wrote:
>
> > In order to send information from one bean to another you can
> use the
> > variable resover or the value binding. When the action to navigate
> > from tree.jsp to editFolder.jsp, you can locate the folderBean
> (if it
> > doesn't exist it'll be created) and set the data you want to send.
> >
> >
> >
> > On 3/30/06, *Dean Hiller* <dean@xsoftware.biz
> <ma...@xsoftware.biz>
> > <mailto: dean@xsoftware.biz <ma...@xsoftware.biz>>> wrote:
> >
> > I am have this
> >
> > treeBean -> tree.jsp
> > folderBean -> editFolder.jsp
> >
> > When someone click on the tree.jsp, I need to fill in the
> folderBean
> > with the folderName, folderId, and folderDescription
> > properties. What
> > is the best design for this? I am quite the newb to all
> this. I am
> > thinking session state right now is easiest, and I retrieve the
> > folderBean in treeBean.editFolder() action method and fill
> it in, so
> > when editFolder.jsp renders, it renders with the correct
> data. Please
> > suggest alternatives and what you think is the best.
> >
> > Lastly, what about dealing with someone who opens up two
> windows(which
> > would be in the same session). Couldn't he possibly step on
> himself
> > since I am storing this stuff in the session above?
> >
> > thanks,
> > dean
> >
> >
>
>
Re: design question...filling in bean, posting
Posted by Ricardo Tercero Lozano <rt...@gmail.com>.
You can get a reference to a managed bean defined in faces-config.xml this
way:
ValueBinding bind = FacesContext.getCurrentInstance
().getApplication()
.createValueBinding("#{myBean}");
MyBean myBean = (MyBean)bind.getValue(this.facesContext);
It can be done too using the variableResolver. El expression can reference a
managed bean or a property (eg. #{myBean.myProperty}. You can get an set a
value.
If myBean doesn't exists, Faces creates a new instance and returns it.
On 3/31/06, Dean Hiller <de...@xsoftware.biz> wrote:
>
> I am not sure I understand. In treeBean, how do I get a folderBean(that
> will be created if it doesn't exist). I was looking at
>
> FacestContext
> ExternalContext
>
> I could not find any methods that I can use to look up "folderBean"(and
> create a FolderBean if one doesn't exist), but I suppose I am just
> missing this. Could you point me to the method?
>
> LASTLY, can this bean be request scoped in this case then? it sounds
> like it to me, but I am a newb in this stuff.
>
> thanks,
> dean
>
> Ricardo Tercero Lozano wrote:
>
> > In order to send information from one bean to another you can use the
> > variable resover or the value binding. When the action to navigate
> > from tree.jsp to editFolder.jsp, you can locate the folderBean (if it
> > doesn't exist it'll be created) and set the data you want to send.
> >
> >
> >
> > On 3/30/06, *Dean Hiller* <dean@xsoftware.biz
> > <ma...@xsoftware.biz>> wrote:
> >
> > I am have this
> >
> > treeBean -> tree.jsp
> > folderBean -> editFolder.jsp
> >
> > When someone click on the tree.jsp, I need to fill in the folderBean
> > with the folderName, folderId, and folderDescription
> > properties. What
> > is the best design for this? I am quite the newb to all this. I am
> > thinking session state right now is easiest, and I retrieve the
> > folderBean in treeBean.editFolder() action method and fill it in, so
> > when editFolder.jsp renders, it renders with the correct
> data. Please
> > suggest alternatives and what you think is the best.
> >
> > Lastly, what about dealing with someone who opens up two
> windows(which
> > would be in the same session). Couldn't he possibly step on himself
> > since I am storing this stuff in the session above?
> >
> > thanks,
> > dean
> >
> >
>
>
Re: design question...filling in bean, posting Missing info added
Posted by Dean Hiller <de...@xsoftware.biz>.
I realized I am not doing a good job at explaining what I am looking
for(partially cause I am new to all this).
I have treeModel that contains the whole tree and all information in an
application context. I have a treebean that usually just passes the ids
of the treenodes back in the tree.jsp so tree.jsp has no knowledge of
any folderBeans as that would be too much I think and unnecessary. When
the action is called for the treeBean, I want to populate the folderBean
that is going to be used by editFolder.jsp, but alas there is no
folderBean at this point. I need my treeBean action method to create
the folderBean such that when editFolder.jsp is used, it uses that newly
created bean. Is something like this possible? Is that bean need to be
session scoped or can I do request scope?
thanks,
dean
Dean Hiller wrote:
> I am not sure I understand. In treeBean, how do I get a
> folderBean(that will be created if it doesn't exist). I was looking at
>
> FacestContext
> ExternalContext
>
> I could not find any methods that I can use to look up
> "folderBean"(and create a FolderBean if one doesn't exist), but I
> suppose I am just missing this. Could you point me to the method?
>
> LASTLY, can this bean be request scoped in this case then? it sounds
> like it to me, but I am a newb in this stuff.
>
> thanks,
> dean
>
> Ricardo Tercero Lozano wrote:
>
>> In order to send information from one bean to another you can use the
>> variable resover or the value binding. When the action to navigate
>> from tree.jsp to editFolder.jsp, you can locate the folderBean (if it
>> doesn't exist it'll be created) and set the data you want to send.
>>
>>
>>
>> On 3/30/06, *Dean Hiller* <dean@xsoftware.biz
>> <ma...@xsoftware.biz>> wrote:
>>
>> I am have this
>>
>> treeBean -> tree.jsp
>> folderBean -> editFolder.jsp
>>
>> When someone click on the tree.jsp, I need to fill in the folderBean
>> with the folderName, folderId, and folderDescription
>> properties. What
>> is the best design for this? I am quite the newb to all this. I am
>> thinking session state right now is easiest, and I retrieve the
>> folderBean in treeBean.editFolder() action method and fill it in, so
>> when editFolder.jsp renders, it renders with the correct data.
>> Please
>> suggest alternatives and what you think is the best.
>>
>> Lastly, what about dealing with someone who opens up two
>> windows(which
>> would be in the same session). Couldn't he possibly step on himself
>> since I am storing this stuff in the session above?
>>
>> thanks,
>> dean
>>
>>
>
Re: design question...filling in bean, posting
Posted by Dean Hiller <de...@xsoftware.biz>.
I am not sure I understand. In treeBean, how do I get a folderBean(that
will be created if it doesn't exist). I was looking at
FacestContext
ExternalContext
I could not find any methods that I can use to look up "folderBean"(and
create a FolderBean if one doesn't exist), but I suppose I am just
missing this. Could you point me to the method?
LASTLY, can this bean be request scoped in this case then? it sounds
like it to me, but I am a newb in this stuff.
thanks,
dean
Ricardo Tercero Lozano wrote:
> In order to send information from one bean to another you can use the
> variable resover or the value binding. When the action to navigate
> from tree.jsp to editFolder.jsp, you can locate the folderBean (if it
> doesn't exist it'll be created) and set the data you want to send.
>
>
>
> On 3/30/06, *Dean Hiller* <dean@xsoftware.biz
> <ma...@xsoftware.biz>> wrote:
>
> I am have this
>
> treeBean -> tree.jsp
> folderBean -> editFolder.jsp
>
> When someone click on the tree.jsp, I need to fill in the folderBean
> with the folderName, folderId, and folderDescription
> properties. What
> is the best design for this? I am quite the newb to all this. I am
> thinking session state right now is easiest, and I retrieve the
> folderBean in treeBean.editFolder() action method and fill it in, so
> when editFolder.jsp renders, it renders with the correct data. Please
> suggest alternatives and what you think is the best.
>
> Lastly, what about dealing with someone who opens up two windows(which
> would be in the same session). Couldn't he possibly step on himself
> since I am storing this stuff in the session above?
>
> thanks,
> dean
>
>
Re: design question...filling in bean, posting
Posted by Ricardo Tercero Lozano <rt...@gmail.com>.
In order to send information from one bean to another you can use the
variable resover or the value binding. When the action to navigate from
tree.jsp to editFolder.jsp, you can locate the folderBean (if it doesn't
exist it'll be created) and set the data you want to send.
On 3/30/06, Dean Hiller <de...@xsoftware.biz> wrote:
>
> I am have this
>
> treeBean -> tree.jsp
> folderBean -> editFolder.jsp
>
> When someone click on the tree.jsp, I need to fill in the folderBean
> with the folderName, folderId, and folderDescription properties. What
> is the best design for this? I am quite the newb to all this. I am
> thinking session state right now is easiest, and I retrieve the
> folderBean in treeBean.editFolder() action method and fill it in, so
> when editFolder.jsp renders, it renders with the correct data. Please
> suggest alternatives and what you think is the best.
>
> Lastly, what about dealing with someone who opens up two windows(which
> would be in the same session). Couldn't he possibly step on himself
> since I am storing this stuff in the session above?
>
> thanks,
> dean
>
>