留言板

how to make field transient in an entity using service builder

Madhu Chandrappa,修改在9 年前。

how to make field transient in an entity using service builder

New Member 帖子: 7 加入日期: 15-1-14 最近的帖子
In a hibernate we can make a field transient using @transient annotation is there any similar option in service builder to make a field transient....

thanks
madhu
thumbnail
David H Nebinger,修改在9 年前。

RE: how to make field transient in an entity using service builder

Liferay Legend 帖子: 14914 加入日期: 06-9-2 最近的帖子
No.
thumbnail
Johann Sonnenberg,修改在6 年前。

RE: how to make field transient in an entity using service builder

New Member 帖子: 20 加入日期: 17-6-28 最近的帖子
You have said "no" to the use of @Transient in service builder, but Liferay must have a mechanism to define transient properties of an entity. I am running into this same problem, and cannot be the first.

Thanks.
thumbnail
David H Nebinger,修改在6 年前。

RE: how to make field transient in an entity using service builder

Liferay Legend 帖子: 14914 加入日期: 06-9-2 最近的帖子
There is no @Transient support.

You can go into your entity's Impl class and add fields and methods there - since they are not part of the entity definition from service.xml, they will not be persisted.

So, for example, I have an Event entity in service.xml. The generated files in blah.blah.model.impl represent the entity impl classes so I have EntityImpl (the one I'm talking about here) and EventModelImpl and EventBaseImpl (that contain all of the SB-generated code for DB persistence).

Any methods I put into EventImpl will be copied to the Event interface the next time I rebuild services, any private member fields I add to the class will be available but not persisted.






Come meet me at Devcon 2017 or 2017 LSNA!
thumbnail
Johann Sonnenberg,修改在6 年前。

RE: how to make field transient in an entity using service builder

New Member 帖子: 20 加入日期: 17-6-28 最近的帖子
I added that private property and the setter/getter methods to the SignupImpl.java and reran Service Builder. It generated everything properly as far as I can tell (I was watching the console and everything came back without errors). Thank you for that!

I now am wanting to use this non-persisted property of verifyEmailAddress in my signup_form.jsp page. On this page, I am using the aui taglibs on my sign up form and have the inputs of course linked via model-context to this bean/entity.

However, the input is not showing when I try to use the new property in that jsp. But, in a scriptlet at the top, it does find the signup.getVerifyEmailAddress() method.

I'm at a loss as to why this would error (silently it seems) and not be able to find that property.

Thoughts?

Thanks!!
thumbnail
David H Nebinger,修改在6 年前。

RE: how to make field transient in an entity using service builder

Liferay Legend 帖子: 14914 加入日期: 06-9-2 最近的帖子
Without seeing the relevant jsp, it's hard to get a full picture...












Come meet me at Devcon 2017 or 2017 LSNA!
thumbnail
Johann Sonnenberg,修改在6 年前。

RE: how to make field transient in an entity using service builder

New Member 帖子: 20 加入日期: 17-6-28 最近的帖子
Hehe yeah that would make sense. Here's a relevant snippet from the jsp.


<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%@ page import="com.blah.Signup"%>

<%
Signup signup = null;
%>

<aui:form action="<%= createAccountURL %>" method="post" name="fm">
       <aui:model-context bean="<%= signup %>" model="<%= Signup.class %>" />

    	<aui:fieldset column="<%= true %>" label="Enter your info to create an account.">
		<aui:col width="<%= 50 %>">
			<aui:input name="firstName" label="First Name">
				<aui:validator name="required" />
			</aui:input>

			<aui:input name="lastName" label="Last Name">
				<aui:validator name="required" />
			</aui:input>

			<aui:input name="emailAddress">
				<aui:validator name="required" />
				<aui:validator name="email" />
			</aui:input>

			<aui:input name="verifyEmailAddress" label="Verify Email Address">
				<aui:validator name="required" />
				<aui:validator name="email" />
			</aui:input> 
		</aui:col>
	</aui:fieldset>
</aui:form>


Thanks!
thumbnail
David H Nebinger,修改在6 年前。

RE: how to make field transient in an entity using service builder

Liferay Legend 帖子: 14914 加入日期: 06-9-2 最近的帖子
What version of Liferay?

It would appear that the JSP does not have the visibility on the new column. Could be because it has an older version of the API jar. Could be because something is out of sync in osgi/state.

One that I'm leaning towards, could be that the JSP didn't change after the API jar was updated, so there's a compiled version of the JSP page in the work directory from the interface version that did not have the column, so it generated a servlet that didn't even try to bind to the field.

So try purging osgi/state and the Liferay work directory contents and restart Liferay to see if that fixes it...








Come meet me at Devcon 2017 or 2017 LSNA!
thumbnail
Johann Sonnenberg,修改在6 年前。

RE: how to make field transient in an entity using service builder

New Member 帖子: 20 加入日期: 17-6-28 最近的帖子
Thanks David.

The version of Liferay I'm using (per the control panel --> server administration) is: Liferay DXP Digital Enterprise 7.0.10 GA1 (Wilberforce / Build 7010 / June 15, 2016)

I stopped Liferay.
Then I deleted everything under {Liferay Home}/osgi/state and under {LIferay Home}/work.
I started Liferay back up.

No change in behavior in the jsp. emoticon

Any other thoughts? I know the module I'm working in has a reference to the api module which defines the Signup entity. Is there some configuration I'm missing? Is there a log folder/file that I could be looking at to find what the underlying error is? The console doesn't spit anything out on this page.

Thanks for your continued help on this!
thumbnail
David H Nebinger,修改在6 年前。

RE: how to make field transient in an entity using service builder

Liferay Legend 帖子: 14914 加入日期: 06-9-2 最近的帖子
What fix pack are you at?










Come meet me at Devcon 2017 or 2017 LSNA!
thumbnail
Johann Sonnenberg,修改在6 年前。

RE: how to make field transient in an entity using service builder

New Member 帖子: 20 加入日期: 17-6-28 最近的帖子
Here's what I got when i ran "sudo ../patching-tool/patching-tool.sh info":
-------------------------
Loading product and patch information...
Product information:
* installation type: binary
* build number: 7010
* service pack version:
- available SP version: 4
- installable SP version: 4
* patching-tool version: 2.0.6
* time: 2017-09-21 14:42Z
* plugins: MyProject-Liferay7-Theme

Currently installed patches: de-22-7010

Available patches: de-22-7010

Detailed patch list:
[*I] de-22-7010 :: Installed; Will be installed. :: Built for LIFERAY
-------------------------

Is this what you are looking for?

Thanks!
thumbnail
David H Nebinger,修改在6 年前。

RE: how to make field transient in an entity using service builder

Liferay Legend 帖子: 14914 加入日期: 06-9-2 最近的帖子
Yep, you're at FP 22 (note that FP31 is out, but I don't think there's anything in there that would address this issue).

So it all should work. Do you have project(s) you can share?









Come meet me at Devcon 2017 or 2017 LSNA!
thumbnail
Johann Sonnenberg,修改在6 年前。

RE: how to make field transient in an entity using service builder

New Member 帖子: 20 加入日期: 17-6-28 最近的帖子
Thanks for verifying the patch level for me. Unfortunately, I cannot share the projects as they are proprietary. Unless of course you work for Liferay and we can open up a support ticket via LESA and you can see it that way. Is this an option?

In the scriptlet in that jsp, I did this:


&lt;%
Signup signup = null;
%&gt;


And, when I started typing "signup." the intellisense popped up and showed the mutator methods for the verifyEmailAddress property. So it seems the jsp (and developer studio) see the new code/link, but for some reason something else does not. Is there an entry or entries in the database that i can look at for this? Any other thoughts?

Thanks again!
thumbnail
David H Nebinger,修改在6 年前。

RE: how to make field transient in an entity using service builder

Liferay Legend 帖子: 14914 加入日期: 06-9-2 最近的帖子
Do you have public getter/setter for the field?









Come meet me at Devcon 2017 or 2017 LSNA!
thumbnail
Johann Sonnenberg,修改在6 年前。

RE: how to make field transient in an entity using service builder

New Member 帖子: 20 加入日期: 17-6-28 最近的帖子
Yup, I sure do. Here is a snippet of my SignupImpl.java


package com.blah.portlet.signup.model.impl;

@ProviderType
public class SignupImpl extends SignupBaseImpl {

	public SignupImpl() {
	}

        private java.lang.String verifyEmailAddress;

	public java.lang.String getVerifyEmailAddress() {
		return verifyEmailAddress;
	}
	
	public void setVerifyEmailAddress(java.lang.String vea) {
		verifyEmailAddress = vea; 
	}
}


Thanks!
thumbnail
David H Nebinger,修改在6 年前。

RE: how to make field transient in an entity using service builder

Liferay Legend 帖子: 14914 加入日期: 06-9-2 最近的帖子
Well, I'm at a loss then. AUI isn't really caring about SB entity vs non-SB entity, so there's nothing in there that points to me what the problem might be...








Come meet me at Devcon 2017 or 2017 LSNA!
thumbnail
Johann Sonnenberg,修改在6 年前。

RE: how to make field transient in an entity using service builder

New Member 帖子: 20 加入日期: 17-6-28 最近的帖子
Thanks for all your help on this!

What I ended up doing was just going with an html input with the proper classes on it and had a little AUI to write for the validation, and BAM it works as intended. I did have to hard code a few things, i.e. the asterisk used for "required", and maybe I didn't but being new to Liferay, that's the route I took.

Here's a few snippets in case anyone else runs into this issue with non-persistent properties of an entity in Liferay.

HTML input in the jsp:

<div class="form-group">
    <label class="control-label" for="<portlet:namespace />verifyEmailAddress">
        Verify Email Address
        <span class="text-warning" id="">
            <svg class="lexicon-icon lexicon-icon-asterisk" focusable="false" role="img" title="" viewbox="0 0 512 512">
                <path class="lexicon-icon-outline" d="M323.6,190l146.7-48.8L512,263.9l-149.2,47.6l93.6,125.2l-104.9,76.3l-96.1-126.4l-93.6,126.4L56.9,435.3l92.3-123.9L0,263.8l40.4-122.6L188.4,190v-159h135.3L323.6,190L323.6,190z"></path>
            </svg>
        </span> 
        <span class="hide-accessible">Required</span> 
    </label>
    <input type="text" name="<portlet:namespace />verifyEmailAddress" id="<portlet:namespace />verifyEmailAddress" class="field form-control" value="<%= verifyEmailAddress %>">
</div>


JavaScript (AUI) code:

<script type="text/javascript">
        //add form validation for the verifyEmailAddress field
	AUI().ready('alloy-node', 'aui-form-validator', function(A) {
	    var formValidator = new A.FormValidator({
	        boundingBox: '#<portlet:namespace />fm', 
	        containerErrorClass: 'myapp-has-error',
	        containerValidClass: 'myapp-has-success',
	        rules: {
	            <portlet:namespace />verifyEmailAddress: {
	            	email: true,
	    	        equalTo: '#<portlet:namespace />emailAddress',
	    	        required: true
	            }
	        },
	        fieldStrings: {
	            <portlet:namespace />verifyEmailAddress: {
	                required: 'Verify email address is required and must match email address.',
	                equalTo: 'Verify email address is required and must match email address.'
	            }
	        },
	        on: {
	            validateField: function(event) {},
	            validField: function(event) {},
	            errorField: function(event) {},
	            submitError: function(event) {
	                var errors = event.validator.errors;
	                event.preventDefault();
	            },
	            submit: function(event) {
	                return false;
	            }
	        }
	    });
	});
</script>


Something to note in the JavaScript code above, is that when I tried to set the containerErrorClass and the containerValidClass to "has-error" and "has-success" it did not work. I had to basically duplicate those classes in my CSS so they would get added properly.

Thanks again for your help. If you have any other suggestions, I'd take 'em!