留言板

Structure customization: Text box should be displayed if condition is true.

Vivek X,修改在8 年前。

Structure customization: Text box should be displayed if condition is true.

New Member 帖子: 3 加入日期: 15-8-14 最近的帖子
Hi Friends,

I have cretaed a structure called myStructure which has 2 fields. One Dropdown and one Text Box. Drop down has 2 options : YES and NO.

In myStructure, If YES is selected then text box should be displayed. If NO is selected then then text box should be hidden. Thats the only requirement.

I am new to Liferay and not getting Idea how to achieve this, which file to modify on which location.
Please suggest some solution OR suggest sample code to follow.

Many Thanks.
Vivek
thumbnail
Andew Jardine,修改在8 年前。

RE: Structure customization: Text box should be displayed if condition is t

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
This has been asked before I am sure -- in fact I remember trying to figure out how to do this myself in the past. The simple answer is that this is not supported out of the box. You could acheive it using a jsp hook but it would be painful. If you do go this route then you would need to figure out which jsp from the portal source is used to render a structure and then add logic (probably JS that is used to show/hide your element) based not only on your value, but based on the structure you need to do it with as the file is (I believe) shared by all structures.
Vivek S,修改在8 年前。

RE: Structure customization: Text box should be displayed if condition is t

New Member 帖子: 3 加入日期: 15-8-14 最近的帖子
Yeah, you pointed correctly that if we implement it through hook, then It is getting applicable to all structures. And that is strictly not required as i have to create more structures which will have their own functionalities. And If those functionalities are reflected in other Structures It will be a total mess I believe emoticon

How can i make changes specifically to a structure itself?.... thats the question bothering me.

Can u please advise me where I can modify the code of the Structure and what is the process to achieve this?

even an example will also be a big help.
Thanks !!
thumbnail
Andew Jardine,修改在8 年前。

RE: Structure customization: Text box should be displayed if condition is t

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
I don't think it is possible to do it to "the structure itself". I never actually tracked down the specific jsp that was used to render the structure as an html form but for sure it is under /html/portlet/journal -- possibly this file? /html/portlet/journal/article/content.jsp?

In terms of targeting just your one structure, if you know the structure id, or the name or something then part of your "branch logic" could be based on detecting that attribute. TYou could even make this a little more robust by adding a property to the portal-ext and using the PrefsPropsUtil to retreive it. You could do something like

web.content.form.with.dependency.fields.structure.names=structureA,structureB,structureC


and then use


String[] dependencyStructures = PrefsPropsUtil.getStringArray("web.content.form.with.dependency.fields.structure.names");


and then in your JSP hook loop or whatever over that list and if the current structure referenced in the JSP is also in that list, show your custom logic -- otherwise, leave the JSP as is.
Vivek S,修改在8 年前。

RE: Structure customization: Text box should be displayed if condition is t

New Member 帖子: 3 加入日期: 15-8-14 最近的帖子
Thank you very much for your reply!!

I tried the above but not getting the desired result.

Earlier we were using Teamsite CMS and were able to edit individual Structure without any hassle. We were using Teamsite Form API to achieve these simple tasks and tougher tasks than this.

There will be number of structures in a project and Structure customization is must as the business needs vary from Structure to structure.
It seems this should be much simple to play with Html Input Tags and their functionality.

The task which is much simple in Teamsite is becoming difficult to achieve in LifeRay emoticon
thumbnail
Olaf Kock,修改在8 年前。

RE: Structure customization: Text box should be displayed if condition is t

Liferay Legend 帖子: 6396 加入日期: 08-9-23 最近的帖子
Out of the box, Liferay does not have conditional rendering for the article editor based on other input. It feels like it would be possible with a few additions though: You can define optional metadata for each field - in it you can, for example, name conditions under which to show certain fields (see the xml source in the structure editor for some of the metadata already in the XML).

The article editor then would need to be modified to take these validations into account. It doesn't look like a trivial change, but it looks doable. Have I done it already or do I have time to do a POC? Sadly no. But this sounds a lot better than hardcoding individual structure ids into the article editor for conditional rendering of the form.

Is this the only solution option? Probably not. It's just the first one that came to my mind when I looked at the structure editor and raw xml description.
thumbnail
Andew Jardine,修改在8 年前。

RE: Structure customization: Text box should be displayed if condition is t

Liferay Legend 帖子: 2416 加入日期: 10-12-22 最近的帖子
Hi Vivek,

I'm not sure how you expect this reply to be in any way helpful. I would also point out that you are on a LIFERAY FORUM so talking about how much better a tool you are already familiar with that is not Liferay and pointing out how one feature is easier in another product says nothing. I am willing to be that there are other feature in Teamsite that are also easier done than Liferay. I am also willing to bet that there are just as many, if not more, features that are available in Liferay that would put team site to shame. Your requirement is Liferay -- so try not to fall into the trap of poo poo'ing Liferay because you already know how to do it with another product.

Perhaps if you post your work, attach your project or something then we can have a look at what you have done and help figure out what is not working and why. That would be a far more productive post.
thumbnail
Olaf Kock,修改在8 年前。

RE: Structure customization: Text box should be displayed if condition is t

Liferay Legend 帖子: 6396 加入日期: 08-9-23 最近的帖子
Great reply. I was thinking of covering this aspect, but couldn't find a good reply - this is the reply that I couldn't put together. Thanks.

Apologies if the reply that I wrote above is too theoretical - it's written between two assignments with no option to quickly try out some POC code. Maybe it helps someone (might even trigger some marketplace App idea. it made it to my ever growing list without a lot of hope to be implemented shortly)

Feel free to discuss more. I might be able to step in with more detailed questions, though not with any POC code any time before Devcon (beginning of October)
Michele Dalla Torre,修改在8 年前。

RE: Structure customization: Text box should be displayed if condition is t

New Member 帖子: 3 加入日期: 15-5-28 最近的帖子
Vivek S:
Thank you very much for your reply!!

I tried the above but not getting the desired result.

Earlier we were using Teamsite CMS and were able to edit individual Structure without any hassle. We were using Teamsite Form API to achieve these simple tasks and tougher tasks than this.

There will be number of structures in a project and Structure customization is must as the business needs vary from Structure to structure.
It seems this should be much simple to play with Html Input Tags and their functionality.

The task which is much simple in Teamsite is becoming difficult to achieve in LifeRay emoticon



Hi @Vivek S, did you manage to solve this issue?

I have the same problem and was wondering if you tried the solution above mentioned.

Thanks,
Michele